<%--
  Created by IntelliJ IDEA.
  User: 86132
  Date: 2022/10/29
  Time: 22:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
%>
<html>
<head>
    <base href="<%= basePath%>">
    <title>Title</title>
    <%--    引入jquery--%>
    <script src="js/jquery-3.6.0.min.js"></script>
</head>

<script type="text/javascript">
    $(function (){
        <%--    给登录按钮绑定单机事件,发送ajax请求--%>
        $("#loginBtn").click(function (){
            //获取用户输入的属性
            var userName=$("#userName").val()
            var password=$("#password").val()
            //身份验证
            if (userName == ""){
                $("#msg").html("用户名不能为空")
                return;
            }
            if (password == ""){
                $("#msg").html("密码不能为空")
                return;
            }
            $.ajax({
                type : "POST",
                url : "settings/qx/user/verify.do",
                data : {
                    userName : userName,
                    password : password
                },
                dataType : "json",
                success : function (resp){
                    if (resp.code == 1){
                        window.location.href="workbench/index.do"
                    }else {
                        $("#msg").html(resp.message)
                    }
                }
            })
        })

    //    给回车键绑定事件
        $(window).keydown(function (e){
            if (e.keyCode == 13){
                $("#loginBtn").click()
            }
        })

    //    给注册按钮添加单击事件
        $("#registerSpan").click(function (){
            window.location.href="settings/qx/user/toRegister.do"
        })
    })
</script>
<style>
    #registerSpan{
        margin-left: 120px;
        cursor: pointer;
        color: blue;
    }
</style>
<body>
    用户名:<input type="text" id="userName"><br>
    密码:<input type="password" id="password"><br>
    <span id="msg"></span>
    <br>
    <input type="button" value="登录" id="loginBtn">
    <span id="registerSpan">注册</span>
<%-- <form>--%>
<%--     用户名:<input type="text" name="userName">--%>
<%--     密码:<input type="password" name="password">--%>
<%--     <input type="button" value="注册" id="registerBtn">--%>
<%-- </form>--%>
</body>
</html>
